<!-- user表单弹窗 -->
<form id="db-form" lay-filter="db-form" class="layui-form model-form">
    <input name="dbId" type="hidden"/>
    <div class="layui-form-item">
        <label class="layui-form-label">文件地址</label>
        <div class="layui-input-block">
            <input name="dbUrl" id="dbUrl" placeholder="例：E://firebird.fdb" type="text" class="layui-input"
                   lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-inline">
            <input name="dbUsername" id="dbUsername" placeholder="请输入连接用户名" value="sysdba" type="text"
                   class="layui-input"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-inline">
            <input name="dbPassword" id="dbPassword" placeholder="请输入连接密码" value="masterkey" type="text"
                   class="layui-input"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
            <input name="note" id="note" placeholder="请输入数据库备注" type="text" class="layui-input"/>
        </div>
    </div>
    <div class="layui-form-item">
        <button class="layui-btn layui-btn-normal" lay-filter="db-test-submit" lay-submit>连接测试</button>
    </div>
    <div class="layui-form-item model-form-footer">
        <button class="layui-btn layui-btn-primary" ew-event="closeDialog" type="button">取消</button>
        <button class="layui-btn" lay-filter="db-form-submit" lay-submit>确定</button>
    </div>
</form>

<script>
    layui.use(['layer', 'admin', 'form', 'upload', 'config'], function () {
        var layer = layui.layer;
        var admin = layui.admin;
        var form = layui.form;
        var db = admin.getTempData('t_db');
        if (db) {
            form.val('db-form', db);
        }
        // 表单提交事件
        form.on('submit(db-form-submit)', function (data) {
            console.log(data.field);
            layer.load(2);
            admin.req('api-db/db/saveOrUpdate', JSON.stringify(data.field), function (data) {
                layer.closeAll('loading');
                if (data.code == 0) {
                    layer.msg(data.msg, {icon: 1, time: 500});
                    admin.finishPopupCenter();
                } else {
                    layer.msg(data.msg, {icon: 2, time: 500});
                }
            }, "POST");
            return false;
        });
        form.on('submit(db-test-submit)', function (data) {
            console.log(data.field);
            layer.load(2);
            admin.req('api-firebird/fireBird/testConnect', JSON.stringify(data.field), function (data) {
                layer.closeAll('loading');
                if (data.code == 0) {
                    layer.alert(data.msg, {icon: 1, title: "连接测试"});
                }else {
                    layer.alert(data.msg, {icon: 2, title: "连接测试"});
                }
            }, "POST");
            return false;
        });
    });
</script>